# -*- coding: utf-8 -*-
# @Time:2021/04/18 16:18
# @Author:Cindy
import os
from time import sleep
import yaml
from selenium import webdriver


class BasePage:

    def __init__(self, driver=None):
        if driver is None:
            # opt = webdriver.ChromeOptions()
            # opt.debugger_address = "127.0.0.1:9222"
            # self.driver = webdriver.Chrome(options=opt)
            # self.driver.implicitly_wait(10)
            # cookies = self.driver.get_cookies()
            # with open("../datas/cookies.yaml", 'w', encoding="utf-8") as f:
            #     yaml.dump(cookies, f)

            self.driver = webdriver.Chrome()
            self.driver.maximize_window()
            self.driver.implicitly_wait(10)
            self.driver.get("https://work.weixin.qq.com/wework_admin/loginpage_wx?")
            for cookie in yaml.safe_load(open('datas/cookies.yaml')):
                self.driver.add_cookie(cookie)
            self.driver.get("https://work.weixin.qq.com/wework_admin/frame#index")
            sleep(5)
        else:
            self.driver = driver
